//
//  AppDelegate.m
//  王宇先_02_植物大战僵尸
//
//  Created by wyx on 16/3/10.
//  Copyright © 2016年 Apon. All rights reserved.
//

#import "AppDelegate.h"
#import "ViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate
-(void)dealloc{
    [_window release];
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    [self.window makeKeyAndVisible];
    ViewController *vc = [[ViewController alloc] init];
    self.window.rootViewController = vc;
    [_window release];
    [vc release];
    /** 设置背景图 */
    UIImageView *backgroundImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"BackGround.png"]];
    backgroundImage.frame = CGRectMake(0, 0, 414, 736);
    [self.window addSubview:backgroundImage];
    [backgroundImage release];
    /** 创建可变数组存僵尸和花照片 */
    NSMutableArray *arrayOfCorpse = [[NSMutableArray alloc] init];
    for (int i = 0; i < 22; i++) {
        NSString *name = [NSString stringWithFormat:@"Zombie%d.tiff",i];
        UIImage *image = [UIImage imageNamed:name];
        [arrayOfCorpse addObject:image];
    }
    //[arrayOfCorpse release];
    NSMutableArray *arrayOfFlower = [[NSMutableArray alloc] init];
    for (int i = 1; i < 43; i++) {
        NSString *name1 = [NSString stringWithFormat:@"flower%d.tiff",i];
        UIImage *image1 = [UIImage imageNamed:name1];
        [arrayOfFlower addObject:image1];
    }
//    [arrayOfFlower release];
    //僵尸一
    UIImageView *imageOfCorpse1 = [[UIImageView alloc] initWithFrame:CGRectMake(300, 100, 100, 150)];
    imageOfCorpse1.animationImages = arrayOfCorpse;
    imageOfCorpse1.animationDuration = 1;
    imageOfCorpse1.animationRepeatCount = 0;
    [imageOfCorpse1 startAnimating];
    [self.window addSubview:imageOfCorpse1];
    [imageOfCorpse1 release];
    //僵尸二
    UIImageView *imageOfCorpse2 = [[UIImageView alloc] initWithFrame:CGRectMake(300, 370, 100, 150)];
    imageOfCorpse2.animationImages = arrayOfCorpse;
    imageOfCorpse2.animationDuration = 1;
    imageOfCorpse2.animationRepeatCount = 0;
    [imageOfCorpse2 startAnimating];
    [self.window addSubview:imageOfCorpse2];
    [imageOfCorpse2 release];
    //僵尸三
    UIImageView *imageOfCorpse3 = [[UIImageView alloc] initWithFrame:CGRectMake(300, 540, 100, 150)];
    imageOfCorpse3.animationImages = arrayOfCorpse;
    imageOfCorpse3.animationDuration = 1;
    imageOfCorpse3.animationRepeatCount = 0;
    [imageOfCorpse3 startAnimating];
    [self.window addSubview:imageOfCorpse3];
    [imageOfCorpse3 release];
    //行走
    [UIView animateWithDuration:18 animations:^{
        imageOfCorpse1.frame = CGRectMake(80, 100, 100, 150);
    }];
    [UIView animateWithDuration:15 animations:^{
        imageOfCorpse2.frame = CGRectMake(80, 370, 100, 150);
    }];
    [UIView animateWithDuration:18 animations:^{
        imageOfCorpse3.frame = CGRectMake(80, 540, 100, 150);
    }];
    //花1
    UIImageView *imageOfFlower1 = [[UIImageView alloc] initWithFrame:CGRectMake(30, 100, 100, 150)];
    imageOfFlower1.animationImages = arrayOfFlower;
    imageOfFlower1.animationDuration = 2;
    imageOfFlower1.animationRepeatCount = 0;
    [imageOfFlower1 startAnimating];
    [self.window addSubview:imageOfFlower1];
    [imageOfFlower1 release];
    //花2
    UIImageView *imageOfFlower2 = [[UIImageView alloc] initWithFrame:CGRectMake(30, 360, 100, 150)];
    imageOfFlower2.animationImages = arrayOfFlower;
    imageOfFlower2.animationDuration = 2;
    imageOfFlower2.animationRepeatCount = 0;
    [imageOfFlower2 startAnimating];
    [self.window addSubview:imageOfFlower2];
    [imageOfFlower2 release];
    
    
    
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
